//
//  FWCTabBar.swift
//  微博项目001
//
//  Created by 樊武超 on 16/4/6.
//  Copyright © 2016年 樊武超. All rights reserved.
//

import UIKit

class FWCTabBar: UITabBar {
    lazy var butn:UIButton={() -> UIButton in
        
    let butn=UIButton()
        
   butn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
     butn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        butn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: UIControlState.Normal)
         butn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
    return butn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
       addSubview(butn)
       
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width:CGFloat=UIScreen.mainScreen().bounds.size.width/5
        let hight:CGFloat=bounds.size.height
        let Y:CGFloat=0
        
        var index:CGFloat=0
        for subView in subviews {
        
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
            
            subView.frame=CGRectMake(index*width, Y, width, hight)
                
                index=index==1 ? 2+1:index+1
            }
            
            if subView.isKindOfClass(UIButton){
            
            subView.frame=CGRectMake(2.0*width,Y, width, hight)
            }
            
          }
    
    }
  
}
